package project.data;

import project.layer.ant.AntLayer;
import project.layer.ant.AntTickListener;
import framework.layer.deployment.storage.Data;

public abstract class EvaporableData extends Data implements AntTickListener{
	
	protected double remainingSmell = 0;
	
	public EvaporableData(){
		AntLayer.getInstance().registerEvaporableData(this);
	}
	@Override
	public long getStorageSize() {
		return 0;
	}
	


	@Override
	public void processAntTick() {
		evaporate();
	}
	
	
	public void evaporate() {
		this.remainingSmell = getRemainingSmell() * getEvaporationRate();
		if(hasEvaporated()){
			removeEvaporableData();
		}
	}
	
	protected void removeEvaporableData(){
		getDataHolder().remove(this);
		AntLayer.getInstance().unregisterEvaporableData(this);
	}



	public abstract double getEvaporationRate();
	
	public abstract double getEvaporationCutOff();
	
	protected abstract EvaporableDataHolder getDataHolder();
	
	public void dropEvaporableData(double smell){
		this.remainingSmell = smell;
	}
	
	public boolean hasEvaporated() {
		return getRemainingSmell() < getEvaporationCutOff();
	}
	
	public boolean hasPheromones(){
		return !(getRemainingSmell() < getEvaporationCutOff());
	}
	
	public double getRemainingSmell(){
		return remainingSmell;
	}
	
	

	
}
